package br.com.PastelaoDaMary.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.com.PastelaoDaMary.entity.Pedido;
import br.com.PastelaoDaMary.entity.Usuario;

public class PedidoDAO {


	private ConexaoBanco conexaoBanco;
	private String query = "";
	
	public PedidoDAO() {
	conexaoBanco = new ConexaoBanco();	
	}

	public void insertPedido(Pedido pedido) throws SQLException {

		Connection conn = null;
		PreparedStatement statement = null;

		try {
			int i = 0;
			conn = conexaoBanco.getConnection();
			query = "INSERT INTO PEDIDO (*****) VALUES (?,?,?,?)";
			
			statement = conn.prepareStatement(query);
			
//			statement.setString(++i, usuario.getLogin());
//			statement.setString(++i, usuario.getSenha());
//			statement.setString(++i, usuario.getNome());
//			statement.setInt(++i, usuario.getNivelAcesso());

			statement.executeUpdate();
			
		} catch (Exception e1) {
			e1.printStackTrace();
		}finally{
			conexaoBanco.closeAll(conn, statement);
		}
	}
	public void updateUsuario(Usuario usuario) throws SQLException {
		
		Connection conn = null;
		PreparedStatement statement = null;
		
		try {
			int i = 0;
			conn = conexaoBanco.getConnection();
			query = "UPDATE USUARIO SET login = ?, senha=?, nome=?, nivelAcesso=? )";
			statement = conn.prepareStatement(query);
			
//			statement.setString(++i, usuario.getLogin());
//			statement.setString(++i, usuario.getSenha());
//			statement.setString(++i, usuario.getNome());
//			statement.setInt(++i, usuario.getNivelAcesso());
			
			statement.executeUpdate();

		} catch (Exception e1) {
			e1.printStackTrace();
		}finally{
			conexaoBanco.closeAll(conn, statement);
		}
		
	}

	public Integer getUltimoPedido() {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement statement = null;
		Integer numeroPedido = null;
		try {
			int i = 0;
			conn = conexaoBanco.getConnection();
			query = "SELECT MAX(numero) FROM PEDIDO";
			statement = conn.prepareStatement(query);
			
			numeroPedido = statement.executeUpdate();

		} catch (Exception e1) {
			e1.printStackTrace();
		}finally{
			conexaoBanco.closeAll(conn, statement);
		}
		return numeroPedido;
	}
	

}
